package com.medical.view.main;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

import org.apache.wicket.Page;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor;
import org.apache.wicket.request.IRequestCycleProcessor;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.medical.view.admin.login.Login;
import com.medical.view.wicket.MedRequestCycle;

 

public class MedApp extends WebApplication {

//	@Override
//	protected void init() {
// 
////        getResourceSettings().setResourceStreamLocator(new MedStreamLocator());
// 
//	}
	public Class<? extends Page> getHomePage() {
		return Login.class;

	}
	
	
//@PersistenceUnit(unitName="DbOperation")
//    private EntityManagerFactory emf;

 
    @Override
    public void init() {
        super.init();
        
        final ApplicationContext context = new ClassPathXmlApplicationContext(
		"applicationContext.xml");
        
//    	addComponentInstantiationListener(new SpringComponentInjector(this));
        
//        emf = Persistence.createEntityManagerFactory("DbOperation");
//        getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() {
//            @Override
//            public boolean isActionAuthorized(Component c, Action a) {
//                return true;
//            }
//            @Override
//            public boolean isInstantiationAuthorized(Class clazz) {
//                if (TemplatePage.class.isAssignableFrom(clazz)) {
//                    if (BookingSession.get().getUser() == null) {
//                        throw new RestartResponseException(HomePage.class);
//                    }
//                }
//                return true;
//            }
//        });
        getMarkupSettings().setCompressWhitespace(true);
//        mountBookmarkablePage("/home", HomePage.class);
//        mountBookmarkablePage("/logout", LogoutPage.class);
//        mountBookmarkablePage("/register", RegisterPage.class);
//        mountBookmarkablePage("/settings", PasswordPage.class);        
    }

//    public RequestCycle newRequestCycle(Request request, Response response) {
//        return new MedRequestCycle(this, (WebRequest) request, response);
//    }

//    @Override
//    public BookingSession newSession(Request request, Response response) {
//        return new BookingSession(request);
//    }

    @Override
    protected IRequestCycleProcessor newRequestCycleProcessor() {
        return new UrlCompressingWebRequestProcessor();
    }

//    @Override
//    protected ISessionStore newSessionStore() {
//        return new HttpSessionStore(this);
//    }

//    @Override
//    protected IConverterLocator newConverterLocator() {
//        ConverterLocator converterLocator = new ConverterLocator();
//        BigDecimalConverter converter = new BigDecimalConverter() {
//            @Override
//            public NumberFormat getNumberFormat(Locale locale) {
//                return DecimalFormat.getCurrencyInstance(Locale.US);
//            }
//        };
//        converterLocator.set(BigDecimal.class, converter);
//        return converterLocator;
//    }
//
//    public EntityManagerFactory getEntityManagerFactory() {
//        return emf;
//    }

}
